//
//  VisitHistoryCell.m
//  Marketing
//
//  Created by Hanen 3G 01 on 16/5/16.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//

#import "VisitHistoryCell.h"
#import "ClientModel.h"

#define STARTX [UIView getWidth:10]

@implementation VisitHistoryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (CGFloat)cellHeight
{
    return 80.0f;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView WithIndex:(NSInteger)Index
{
    static NSString *DailRecordId = @"uuuuID";
    VisitHistoryCell * cell = [tableView dequeueReusableCellWithIdentifier:DailRecordId];
    if (!cell) {
        cell = [[VisitHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DailRecordId];
        [cell addSubviews];
    }
    return cell;
    
}
- (void)addSubviews
{
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, [VisitHistoryCell cellHeight])];
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:backgroundView];
    
    self.companyLabel = [ViewTool getLabelWith:CGRectMake(STARTX, 10, KSCreenW - 40 - 80, 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:blackFontColor WithTextAlignment:NSTextAlignmentLeft];
    [ViewTool setLableFont14:self.companyLabel];
    [backgroundView addSubview:self.companyLabel];
    
    self.timeLabel = [ViewTool getLabelWith:CGRectMake(KSCreenW - STARTX - 120 , 10, 120.0f, 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:UIColorFromRGB(0xa3a3a3) WithTextAlignment:NSTextAlignmentRight];
    
    [backgroundView addSubview:self.timeLabel];
    
    self.TelManLabel = [ViewTool getLabelWith:CGRectMake(_companyLabel.x, _companyLabel.maxY, 150.0f, 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:UIColorFromRGB(0xa3a3a3)  WithTextAlignment:NSTextAlignmentLeft];
    [backgroundView addSubview:self.TelManLabel];
    
    
    self.responseLabel = [ViewTool getLabelWith:CGRectMake(_TelManLabel.x, _TelManLabel.maxY, 150.0f, 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:UIColorFromRGB(0xa3a3a3)  WithTextAlignment:NSTextAlignmentLeft];
    [backgroundView addSubview:self.responseLabel];
    
    
    self.statusLabel = [ViewTool getLabelWith:CGRectMake(KSCreenW - STARTX - 50.0f, _responseLabel.y, 50.0f, 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:greenBackColor WithTextAlignment:NSTextAlignmentRight];
    [backgroundView addSubview:self.statusLabel];
    
    
    self.alreadVisitImage = [[UIImageView alloc] initWithFrame:CGRectMake(KSCreenW - STARTX - 40, _timeLabel.maxY, 40, 40.0f)];
    self.alreadVisitImage.image = [UIImage imageNamed:@"HY_list_icon_visited"];
    [backgroundView addSubview:self.alreadVisitImage];
    
    _lineView = [[UIView alloc]init];
    _lineView.backgroundColor = grayLineColor;
    [backgroundView addSubview:_lineView];
    
}

- (void)setModel:(ClientModel *)model
{
    _model = model;
    self.companyLabel.text = model.company;
    if (model.status == 1) {
        self.alreadVisitImage.hidden = NO;
        self.statusLabel.hidden = YES;
    }else{
        self.alreadVisitImage.hidden = YES;
        self.statusLabel.hidden = NO;
        if (model.status == 0) {
            self.statusLabel.text = @"待拜访";
        }else if (model.status == 2){
            self.statusLabel.text = @"未拜访";
        }else{
            self.statusLabel.text = @"拜访中";
        }
    }
    
    self.responseLabel.text = [NSString stringWithFormat:@"负责人:%@",model.name];
    self.TelManLabel.text = [NSString stringWithFormat:@"联系人:%@",model.cname];
    self.timeLabel.text = model.ordertime;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
